package croppingplanap;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

public class NorthPanel extends JPanel{
	
	private boolean ready = false;
	private char north;
	static private final Color NORTH_COLOR = Color.black;
	
	public NorthPanel(char north){
		Dimension d = new Dimension(140, 60);
		this.north = north;
		ready = false;
		this.setMinimumSize(d);
		this.setPreferredSize(d);
	}
	
	public void paint(Graphics g){
		if(ready){
			drawArrow(g);
		}
	}
	
	private void drawArrow(Graphics g){
		int xFifth = this.getWidth() / 5;
		int yFifth = this.getHeight() / 5;
		int xCenter = this.getWidth() / 2;
		int yCenter = this.getHeight() / 2;
		
		int[] xTri = new int[3];
		int[] yTri = new int[3];
		
		int xText;
		int yText;
		
		g.setColor(NORTH_COLOR);
		
		if(north == 'u' || north == 'd'){
			g.drawLine(xCenter, yFifth, xCenter, 4 * yFifth);
			xTri[0] = xCenter;
			xTri[1] = xCenter - 4;
			xTri[2] = xCenter + 4;
			
			xText = xCenter + 7;
			yText = yCenter + 4;
			
			if(north == 'u'){
				yTri[0] = yFifth;
				yTri[1] = 2 * yFifth;
				yTri[2] = 2 * yFifth;
			}else{
				yTri[0] = 4 * yFifth;
				yTri[1] = 3 * yFifth;
				yTri[2] = 3 * yFifth;
			}
		}else if(north == 'l' || north == 'r'){
			g.drawLine(xFifth, yCenter, 4 * xFifth, yCenter);
			yTri[0] = yCenter;
			yTri[1] = yCenter - 4;
			yTri[2] = yCenter + 4;
			
			xText = xCenter - 14;
			yText = yCenter - 6;
			
			if(north == 'l'){
				xTri[0] = xFifth;
				xTri[1] = 2 * xFifth;
				xTri[2] = 2 * xFifth;
			}else{
				xTri[0] = 4 * xFifth;
				xTri[1] = 3 * xFifth;
				xTri[2] = 3 * xFifth;
			}
		}else{
			g.drawString("Invalid North Parameter", 1, 3 * yFifth);
			g.drawString("I can't tell where north is", 1, 4 * yFifth);
			return;
		}
		
		g.fillPolygon(xTri, yTri, 3);
		g.drawString("North", xText, yText);
	}
	
	public void setReady(){
		ready = true;
	}
	
}
